﻿<src:OverlayWindow x:Class="GW2PAO.Views.WebBrowser.BrowserView"
        x:Name="webWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:src="clr-namespace:GW2PAO.Views"
        xmlns:awe="http://schemas.awesomium.com/winfx"
        xmlns:data="http://schemas.awesomium.com/winfx/data"
        xmlns:awecore="clr-namespace:Awesomium.Core;assembly=Awesomium.Core"
        xmlns:converters="clr-namespace:GW2PAO.Style.Converters"
        xmlns:core="clr-namespace:GW2PAO.PresentationCore;assembly=GW2PAO.PresentationCore"
        AllowsTransparency="True" WindowStyle="None"
        Background="Transparent"
        ResizeMode="CanResizeWithGrip"
        Height="700" Width="1200">

    <src:OverlayWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Style/ResourceLibrary.xaml" />
            </ResourceDictionary.MergedDictionaries>
            
            <awe:WebSessionProvider x:Key="webSession" DataPath=".\Cache">
                <awecore:WebPreferences  ShrinkStandaloneImagesToFit="False" SmoothScrolling="True"
                                         AllowInsecureContent="False"
                                         CustomCSS="
                                            ::-webkit-scrollbar              { background-color: #000000; }
                                            ::-webkit-scrollbar-button       { background-color: #000000; }
                                            ::-webkit-scrollbar-track        { background-color: #000000 }
                                            ::-webkit-scrollbar-track-piece  { background-color: #000000 }
                                            ::-webkit-scrollbar-thumb        { background-color: #FFA500; }
                                            ::-webkit-scrollbar-corner       { background-color: #000000 }
                                            ::-webkit-resizer                { background-color: #000000 }" />
            </awe:WebSessionProvider>
            
            <awe:UrlConverter x:Key="UrlConverter" />
            <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />

            <DockPanel x:Key="BackGraphic" Height="10">
                <Path HorizontalAlignment="Center" VerticalAlignment="Center"
                      Stretch="Uniform"
                      Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      StrokeStartLineCap="Round" StrokeEndLineCap="Round"
                      StrokeThickness="1"
                      Fill="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      Data="M 0,40 L 20,20 20,32 60,32 60,48 20,48 20,60 0,40">
                </Path>
            </DockPanel>

            <DockPanel x:Key="ForwardGraphic" Height="10">
                <Path HorizontalAlignment="Center" VerticalAlignment="Center"
                      Stretch="Uniform"
                      Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      StrokeStartLineCap="Round" StrokeEndLineCap="Round"
                      StrokeThickness="1"
                      Fill="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      Data="M 60,20 L 40,40 40,28 0,28 0,12 40,12 40,0 60,20">
                </Path>
            </DockPanel>

            <DockPanel x:Key="ReloadGraphic" Height="15">
                <Path HorizontalAlignment="Center" VerticalAlignment="Center"
                      Stretch="Uniform"
                      Stroke="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      StrokeStartLineCap="Round" StrokeEndLineCap="Round"
                      StrokeThickness="1"
                      Fill="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}"
                      Data="M 0,200   C 0,100 75,0 200,0   C 300,0 400,75 400,200  L 450,200  L 375,300  L 300,200  L 350,200  C 350,100 275,50 200,50  C 100,50 50,125 50,200 C 50,250 100,350 200,350  L 200,400  C 100,400 0,300 0,200">
                </Path>
            </DockPanel>
        </ResourceDictionary>
    </src:OverlayWindow.Resources>

    <awe:WebDialogsLayer>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Border Name="TitleBar" Style="{StaticResource TitleBarStyle}"
                    MouseLeftButtonDown="TitleBar_MouseLeftButtonDown"
                    Grid.Row="0">
                <Grid>
                    <Grid.Background>
                        <RadialGradientBrush Opacity="0.5" Center="0,0" GradientOrigin="0,0" RadiusX="1" RadiusY="1">
                            <GradientStop Color="#FF5B4411" Offset="0"/>
                            <GradientStop Color="#015B4411" Offset="1"/>
                        </RadialGradientBrush>
                    </Grid.Background>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="35" />
                        <ColumnDefinition Width="35" />
                    </Grid.ColumnDefinitions>

                    <Image Name="TitleImage"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           Height="30" Width="30"
                           Margin="5,0,0,0"
                           Source="/Resources/community.png"
                           MouseDown="TitleImage_MouseDown">
                        <Image.ContextMenu>
                            <ContextMenu>
                                <!--Should probably do this in a better way... but this will work for now-->
                                <MenuItem Name="WikiLink" Header="GW2 Wiki" Click="BookmarkLink_Click" />
                                <MenuItem Name="DulfyLink" Header="Dulfy" Click="BookmarkLink_Click" />
                                <MenuItem Name="SpidyLink" Header="GW2 Spidy" Click="BookmarkLink_Click" />
                                <Separator />
                                <MenuItem Header="Close" Click="CloseWindowButton_Click" />
                            </ContextMenu>
                        </Image.ContextMenu>
                        <Image.Style>
                            <Style TargetType="{x:Type Image}">
                                <Setter Property="Effect">
                                    <Setter.Value>
                                        <DropShadowEffect ShadowDepth="0"
                                              Color="Goldenrod"
                                              Opacity="0"
                                              BlurRadius="25"/>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Trigger.EnterActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation To="1"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.1"/>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </Trigger.EnterActions>
                                        <Trigger.ExitActions>
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation To="0"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:0.1"/>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </Trigger.ExitActions>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>

                    <!--Navigation Buttons-->
                    <Button Grid.Column="1" Grid.Row="0"
                            Margin="35,5,1,5" Width="30"
                            HorizontalAlignment="Right"
                            Style="{StaticResource TitleBarButtonStyle}"
                            Content="{StaticResource BackGraphic}"
                            Command="{x:Static NavigationCommands.BrowseBack}" 
                            CommandTarget="{Binding ElementName=webControl}"/>

                    <Button Grid.Column="2" Grid.Row="0"
                            Margin="1,5,1,5" Width="30"
                            HorizontalAlignment="Left"
                            Style="{StaticResource TitleBarButtonStyle}"
                            Content="{StaticResource ForwardGraphic}"
                            Command="{x:Static NavigationCommands.BrowseForward}" 
                            CommandTarget="{Binding ElementName=webControl}"/>

                    <Button Grid.Column="3" Grid.Row="0"
                            Margin="1,5,5,5" Width="30" 
                            HorizontalAlignment="Left"
                            Style="{StaticResource TitleBarButtonStyle}"
                            Content="{StaticResource ReloadGraphic}"
                            Command="{x:Static NavigationCommands.Refresh}" 
                            CommandParameter="False"
                            CommandTarget="{Binding ElementName=webControl}"/>

                    <!-- URL Text Box-->
                    <TextBox Grid.Column="4" Grid.Row="0"
                             Margin="5" Padding="3,0"
                             VerticalContentAlignment="Center"
                             TextWrapping="NoWrap"
                             FontFamily="Candara" FontSize="14"
                             Text="{data:SourceBinding webControl}">
                        <TextBox.Background>
                            <LinearGradientBrush>
                                <GradientStop Color="#70000000" Offset="0"/>
                                <GradientStop Color="#00000000" Offset="1"/>
                            </LinearGradientBrush>
                        </TextBox.Background>
                    </TextBox>
                    
                    <!-- Opacity Slider -->
                    <Slider Grid.Column="5" Grid.Row="0" MinWidth="75"
                            Margin="10,0,10,0"
                            VerticalAlignment="Center" HorizontalAlignment="Center"
                            Maximum="1" Minimum="0"
                            Value="{Binding ElementName=webControl, Path=Opacity}" />

                    <!-- Minimize and Close Buttons -->
                    <Button Name="CollapseExpandButton"
                            Grid.Column="6" Grid.Row="0"
                            Margin="5"
                            Click="CollapseExpandButton_Click">
                        <Button.Style>
                            <Style TargetType="Button" BasedOn="{StaticResource TitleBarButtonStyle}">
                                <Setter Property="Content" Value="{StaticResource CollapseGraphic}" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Visibility, ElementName=webControl}" Value="Collapsed">
                                        <DataTrigger.Setters>
                                            <Setter Property="Content" Value="{StaticResource ExpandGraphic}" />
                                        </DataTrigger.Setters>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </Button>

                    <Button Name="CloseWindowButton"
                            Grid.Column="7" Grid.Row="0"
                            Margin="5"
                            Style="{StaticResource TitleBarButtonStyle}"
                            Content="{StaticResource CloseGraphic}"
                            Click="CloseWindowButton_Click" />

                </Grid>
            </Border>

            <awe:WebControl x:Name="webControl" 
                            Grid.Row="1" 
                            NativeView="{Binding NativeView, ElementName=webWindow}"
                            WebSession="{Binding Source={StaticResource webSession}}"
                            Source="{Binding Source, ElementName=webWindow}"
                            Opacity="0.75"/>
        </Grid>
    </awe:WebDialogsLayer>
</src:OverlayWindow>
